﻿var wzPlugin = function () {
    var sLocation = window.location.href;
    console.log(sLocation);
    if ((sLocation.indexOf("blog.csdn.net") > -1) && (oReadButton = document.getElementById('btn-readmore'))) {
        oReadButton.click();
        console.log("这是CSDN网站，已经自动加载全文");
    } else if (sLocation.indexOf("360doc.com") > -1 && (oLayerLogin = document.getElementById('LayerLogin'))) {
        oLayerLogin.parentNode.removeChild(oLayerLogin);
        scriptNode = document.createElement("script");
        scriptNode.innerHTML += "\n\
           document.body.oncopy =null;\n\
           function copyArt(){return true}";
        document.body.appendChild(scriptNode);

    } else if (sLocation.indexOf("readers365.com") > -1) {
        console.log("readers365");
        let paging;
        if ((paging = document.getElementById('object1')) != null) {
            paging.style.position = "fixed";
            console.log("readers365 fixed");
        }
    } else if (sLocation.indexOf("wenku.baidu.com") > -1) {
        console.log("百度文库");
        var scriptNode = document.createElement("script");
        docNode = document.getElementsByClassName("doc-reader");
        copyBtn = document.getElementById("ZeroClipboardMovie_1");
        //scriptNode.innerHTML += "console.log(94565464564564564564564)";
        scriptNode.innerHTML += "\n" +
                "a= document.getElementById(\"reader-container-1\");" +
                "$(a).off('copy');" +
                "docNode=$(\"div.bd.doc-reader\");" +
                "docNode.get(0).removeAttribute(\"oncopy\");" +
                "console.log(\"可以复制\");";
        document.body.appendChild(scriptNode);
    }


    var requestData = {"action": "createContextMenuItem"};
    //send request to background script
    chrome.extension.sendRequest(requestData);


    function genericOnClick(info, tab) {
        alert(info.linkUrl);
    }

    function selectionOnClick(info, tab) {
        alert(info.selectionText);
    }

    /*chrome.contextMenus.create({"title": "链接地址","contexts":["link"],"onclick":genericOnClick});
    selection = chrome.contextMenus.create({"title": "选中文字","contexts":["selection"],"onclick":selectionOnClick});*/
};

wzPlugin();
window.addEventListener("DOMContentLoaded", function (e) {  //添加DOMContentLoaded事件
    console.log("window.addEventListener", e)

}, false);

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
    console.log("chrome.runtime.onMessage.addListener");
    console.log(request, sender, sendResponse);
// code...
// sendResponse('我已收到你的消息：' +JSON.stringify(request));//做出回应
});